package com.example.administrator.wallet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.wallet.R;
import com.example.administrator.wallet.intf.IRequestManager;
import com.example.administrator.wallet.model.bean.CurrencyStatuBean;

import java.util.List;

/**
 * Effect:
 * <p>
 * Author:  CaiYapeng
 * <p>
 * Time  :  2018/8/1.
 */
public class AddCurrencyAdapter extends BaseAdapter {
    private Context context;
    private List<CurrencyStatuBean.DataBean> dataBeen;
    private IRequestManager manager;
    private String statu;
    private String token;
    private OnClickPosition click;

    public AddCurrencyAdapter(Context context, List<CurrencyStatuBean.DataBean> dataBeen, String token) {
        this.context = context;
        this.dataBeen = dataBeen;
        this.token=token;
    }

    @Override
    public int getCount() {
        return dataBeen.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final CurrencyStatuBean.DataBean dataBean = dataBeen.get(i);
        final ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = View.inflate(context, R.layout.item_currency_list, null);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.coin_icon = (ImageView) view.findViewById(R.id.coin_icon);
        holder.coin_name = (TextView) view.findViewById(R.id.coin_name);
        holder.coin_pName = (TextView) view.findViewById(R.id.coin_pName);
        holder.statu = (ImageView) view.findViewById(R.id.statu);


        Glide.with(context).load(dataBean.getIcon()).into(holder.coin_icon);
        holder.coin_name.setText(dataBean.getCoin_symbol());
        if(dataBean.getStatus().equals("1")){
            holder.statu.setSelected(true);
        }else{
            holder.statu.setSelected(false);
        }

        holder.statu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(holder.statu.isSelected()){
                    holder.statu.setSelected(false);
                    statu="off";
                }else{
                    holder.statu.setSelected(true);
                    statu="on";
                }

                click.getPosition(dataBean,statu);
            }
        });
        return view;
    }

    private class ViewHolder {
        private ImageView coin_icon;
        private TextView coin_name;
        private TextView coin_pName;
        private ImageView statu;
    }

    public void position(OnClickPosition click) {
        this.click = click;
    }


    public interface OnClickPosition {
        void getPosition(CurrencyStatuBean.DataBean bean,String statu);
    }
}
